#include "TestState.h"
#include "ComboEntity.h"
#include "Connector.h"


ComboEntity::ComboEntity(int xPos, int yPos, int combotype, TestEntity* t1, TestEntity* t2){

    switch(combotype){

    case REVOLUTE:{

         //joint anchor
        TestEntity* ent1 = new TestEntity(EDGE, sf::Vector2f(xPos,yPos), sf::Vector2f(5,5));
        b2Body* bodyA = ent1->getBody();
        //joint second body
        TestEntity* ent2 = new TestEntity(BOX, sf::Vector2f(xPos + 10, yPos + 30), "resources/box2.png");
        b2Body* bodyB = ent2->getBody();

        new Connector(ent1,ent2);

        b2RevoluteJointDef jointDef;
        jointDef.Initialize(bodyA, bodyB, bodyA->GetWorldCenter());
        jointDef.lowerAngle = -0.5f * b2_pi; // -90 degrees
        jointDef.upperAngle = 0.25f * b2_pi; // 45 degrees
        jointDef.enableLimit = false;
        jointDef.maxMotorTorque = 1000.0f;
        jointDef.motorSpeed = 5.0f;
        jointDef.enableMotor = true;
        bodyB->GetWorld()->CreateJoint(&jointDef);
        break;
    }

    case PRISMATIC:{

        //Prismatic joint anchor
        TestEntity* ent1 = new TestEntity(EDGE, sf::Vector2f(xPos,yPos), sf::Vector2f(5,5), -45);
        TestState::EntityList.push_back(ent1);
        b2Body* bodyC = TestState::EntityList.back()->getBody();
        //Prismatic joint second body
        TestEntity* ent2 = new TestEntity(BOX, sf::Vector2f(xPos,yPos), sf::Vector2f(10,50), -45);
        b2Body* bodyD = TestState::EntityList.back()->getBody();

        new Connector(ent1,ent2);

        b2PrismaticJointDef jointDef2;
        b2Vec2 worldAxis(1.0f, -1.0f);
        jointDef2.Initialize(bodyC, bodyD, bodyC->GetWorldCenter(), worldAxis);
        jointDef2.lowerTranslation = 0.0f;
        jointDef2.upperTranslation = 1.0f;
        jointDef2.enableLimit = true;
        jointDef2.maxMotorForce = 5.0f;
        jointDef2.motorSpeed = 3.0f;
        jointDef2.enableMotor = true;
        bodyC->GetWorld()->CreateJoint(&jointDef2);
        break;

    }

    case DISTANCE:{
          //joint anchor
        b2Body* bodyE = t1->getBody();
        //joint second body
        b2Body* bodyF = t2->getBody();

        new Connector(t1,t2);

        b2DistanceJointDef jointDef3;

        jointDef3.frequencyHz = 1.0f;

        jointDef3.dampingRatio = 0.8f;

        jointDef3.Initialize(bodyE, bodyF, bodyE->GetWorldCenter(), bodyF->GetWorldCenter());
        bodyE->GetWorld()->CreateJoint(&jointDef3);
        break;
    }


    }




}
